(defpackage :action-examples
  (:use :cl)
  (:export
   :define-button-example
   :compile-button-example
   :define-action-examples))

(in-package :action-examples)

;; button
(defun define-button-example ()
  (spinneret:with-html
    (:div (:h3 "Button")
          (dui:button "btn" "Button")
          (dui:button "btn btn-neutral" "Neutral")
          (dui:button "btn btn-primary" "Primary"))))

;; dropdown
(defun define-dropdown-example ()
  (spinneret:with-html
    (:div (:h3 "Dropdown")
          (dui:dropdown/details "dropdown" (dui:summary "Dropdown menu using <details> tag" "btn m-1")
            (:ul :class "menu dropdown-content bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
                 (:li (:a "Item 1"))
                 (:li (:a "Item 2"))
                 ))
          (dui:dropdown/css-focus "dropdown" (dui:tabindex "Dropdown menu using CSS focus" "btn m-1" "0" "button")
            (:ul :tabindex "0" :class "dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
                 (:li (:a "Item 1"))
                 (:li (:a "Item 2"))
                 ))
          (dui:dropdown/css-focus "dropdown dropdown-hover" (dui:tabindex "Open on hover" "btn m-1" "0" "button")
            (:ul :tabindex "0" :class "dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
                 (:li (:a "Item 1"))
                 (:li (:a "Item 2"))
                 ))
          (dui:dropdown/css-focus "dropdown" (dui:tabindex "Card as dropdown" "btn m-1" "0" "button")
            (:div :tabindex "0" :class "dropdown-content card card-compact bg-primary text-primary-content z-[1] w-64 p-2 shadow"
                  (:div :class "card-body"
                        (:h3 :class "card-title" "Card title!")
                        (:p "you can use any element as a dropdown.")
                        ))))))

(defun define-modal-example ()
  (spinneret:with-html
    (:div (:h3 "Modal")
          (dui:modal/dialog "modal" "my_modal_1"
              (dui:button "btn" "Dialog modal" :onclick "my_modal_1.showModal()")
            (:div :class "modal-box"
                  (:h3 :class "text-lg font-bold" "Hello")
                  (:p :class "py-4" "Press ESC key or click the button below to close.")
                  (:div :class "modal-action"
                        (:form :method "dialog"
                               (dui:button "Close" "btn")))))
          (dui:modal/dialog "modal" "my_modal_2"
              (dui:button "btn" "Dialog modal, closes when clicked outside" :onclick "my_modal_2.showModal()")
            (:div :class "modal-box"
                  (:h3 :class "text-lg font-bold" "Hello")
                  (:p :class "py-4" "Press ESC key or click the button below to close."))
            (:form :method "dialog" :class "modal-backdrop"
                   (dui:button "Close" ""))))))

(defun define-swap-example ()
  (spinneret:with-html
    (:div (:h3 "Swap")
          (dui:swap "swap")
          (:label :class "swap"
                  (:input :type "checkbox")
                  (:div :class "swap-on" "ON")
                  (:div :class "swap-off" "OFF"))
          (dui:swap "swap swap-flip text-9xl"
              (:div :class "swap-on" "😈")
              (:div :class "swap-off" "😇")))))

(defun define-action-examples ()
  (spinneret:with-html
    (:div
     (define-button-example)
     (define-dropdown-example)
     (define-modal-example)
     (define-swap-example)
     )))

(defun compile-button-example ()
  (spinneret:with-html-string
    (define-button-example)))

(defun compile-dropdown-example ()
  (spinneret:with-html-string
    (define-dropdown-example)))

(defun compile-modal-example ()
  (spinneret:with-html-string
    (define-modal-example)))

(defun compile-swap-example ()
  (spinneret:with-html-string
    (define-swap-example)))

(easy-routes:defroute actions-button ("/actions/button" :method :get) ()
  (compile-button-example))

(easy-routes:defroute actions-dropdown ("/actions/dropdown" :method :get) ()
  (compile-dropdown-example))

(easy-routes:defroute actions-modal ("/actions/modal" :method :get) ()
  (compile-modal-example))

(easy-routes:defroute actions-swap ("/actions/swap" :method :get) ()
  (compile-swap-example))
